{extend name="../../base/view/common/base" /}
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">新建任务</h3>
	<table class="layui-table layui-table-form">
		<tr>
			<td class="layui-td-gray">任务主题<font>*</font></td>
			<td colspan="3">
				<input type="text" name="title" lay-verify="required" lay-reqText="请输入任务主题" placeholder="请输入任务主题" class="layui-input" value="">
			</td>
			<td class="layui-td-gray">优先级<span style="color: red">*</span></td>
			<td>
				<select name="priority" lay-verify="required" lay-reqText="请选择优先级">
					<option value="1" selected>低</option>
					<option value="2">中</option>
					<option value="3">高</option>
					<option value="4">紧急</option>
				</select>
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">工作类型<span style="color: red">*</span></td>
			<td>
				<select name="cate" lay-verify="required" lay-reqText="请选择工作类型">
					<option value="">请选择</option>
					{volist name="cate" id="vo"}
					<option value="{$vo.id}">{$vo.title}</option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray">预估工时<span style="color: red">*</span></td>
			<td>
				<input type="text" name="plan_hours" lay-verify="required" lay-reqText="请填写预估工时" placeholder="请填写预估工时" class="layui-input" value="">
			</td>
			<td class="layui-td-gray-2">预计结束日期<span style="color: red">*</span></td>
			<td>
				<input type="text" id="end_time" name="end_time" readonly lay-verify="required" lay-reqText="请选择结束时间" placeholder="请选择时间" class="layui-input" value="">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">负责人</td>
			<td>
				<input type="text" name="director_name" placeholder="请选择" readonly class="layui-input picker-one" value="">
				<input type="hidden" name="director_uid" readonly value="">
			</td>
			<td class="layui-td-gray">协作人</td>
			<td colspan="3">
				<input type="text" name="assist_admin_names" placeholder="请选择" readonly class="layui-input picker-more" value="">
				<input type="hidden" name="assist_admin_ids" readonly value="">
			</td>
		</tr>
		{empty name="$project_id"}
		<tr>
			<td class="layui-td-gray">前置任务</td>
			<td colspan="5">
				<input type="text" name="before_task_name" readonly placeholder="请选择前置任务" class="layui-input picker-task" value="">
				<input type="hidden" name="before_task" readonly value="">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">关联项目</td>
			<td colspan="5">
				<input type="text" name="project_name" readonly placeholder="请选择关联项目" class="layui-input picker-project" value="">
				<input type="hidden" name="project_id" readonly value="">
			</td>
		</tr>
		{else/}
			<tr>
				<td class="layui-td-gray">前置任务</td>
				<td colspan="5">
					<input type="text" name="before_task_name" readonly placeholder="请选择前置任务" class="layui-input picker-task" value="">
					<input type="hidden" name="before_task" readonly value="">
					<input type="hidden" name="project_id" readonly value="{$project_id}">
				</td>
			</tr>
		{/empty}
		<tr>
			<td class="layui-td-gray" style="vertical-align:top;">详细描述<font>*</font></td>
			<td colspan="5">
			  <textarea name="content" placeholder="请输入内容" class="layui-textarea" id="container" style="border:0;padding:0"></textarea>
			</td>
		</tr>
	</table>
	<div style="padding-top: 10px">
		<input type="hidden" name="id" value="0" />
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','tinymce','employeepicker','oaTool'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool, laydate = layui.laydate;
		
		//编辑器初始化
		var editor = layui.tinymce;
		var edit = editor.render({
			selector: "#container",
			images_upload_url: '/api/index/upload/sourse/tinymce',//图片上传接口
			height: 492
		});

		//日期范围
		laydate.render({
			elem: '#end_time'
		});

		//监听提交
		form.on('submit(webform)', function (data) {
		  data.field.content = tinyMCE.editors['container'].getContent();
				if (data.field.content == '') {
					layer.msg('请先完善任务描述内容');
					return false;
				}
		  let callback = function (e) {
				layer.msg(e.msg);
				parent.layui.taskTable.reload();
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/project/task/add", data.field, callback);
			return false;
		});

  }

</script>
{/block}